package org.meb.conquest.web.model;

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import org.apache.commons.lang.StringUtils;
import org.meb.conquest.db.model.Faction;
import org.meb.conquest.db.model.loc.Card;

@Getter
@Setter
public class CardItem {

	@NonNull
	private Card card;
	private Integer quantity = 0;
	private Integer totalCost;
	private String traits[] = new String[3];

	public CardItem(Card card) {
		this(card, 0);
	}
	
	public CardItem(Card card, Integer quantity) {
		this.card = card;
		this.quantity = quantity;

//		increaseTotalCost(card.getCost());
//		increaseTotalCost(card.getCostExtra());

		if (StringUtils.isNotBlank(card.getTrait())) {
			traits = card.getTrait().split("\\.", -1);
			for (int i = 0; i < traits.length; i++) {
				traits[i] = StringUtils.trimToNull(traits[i]);
				if (traits[i] != null) {
					traits[i] += ".";
				}
			}
		}
	}

	private void increaseTotalCost(Integer cost) {
		if (cost != null) {
			if (totalCost == null) {
				totalCost = 0;
			}
			totalCost += cost;
		}
	}

	public boolean isFactionImageAvailable() {
		return card.getFaction() != Faction.NEUTRAL;
	}
}
